package com.halobits.thenumbergames;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;


public class SetupActivity extends ActionBarActivity {

  protected SeekBar seekBar;
  protected TextView gridSize;
  protected Button startClassicButton;

  public final static String GRID_SIZE = "com.halobits.thenumbergames.intentGridSize";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setup);
    init();

    seekBar.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          int progress = 1;

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            this.progress = progress;
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {

          }

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            gridSize.setText(String.valueOf(progress + 2) + " x " + String.valueOf(progress + 2));
          }
        }
    );

    AdView mAdView = (AdView)findViewById(R.id.adView_ad);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
  }

  protected void init() {
    this.seekBar = (SeekBar)findViewById(R.id.set_gridsize);
    this.gridSize = (TextView)findViewById(R.id.text_gridsize);
    this.startClassicButton = (Button)findViewById(R.id.btn_startclassic);
  }

  public void startClassicActivity(View view) {
    Intent i = new Intent(this, ClassicActivity.class);
    i.putExtra(GRID_SIZE, seekBar.getProgress());
    startActivity(i);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_setup, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
}
